package com.azxcrm.project.system.wap.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.azxcrm.common.utils.security.ShiroUtils;
import com.azxcrm.project.system.customer.domain.CustomerClue;
import com.azxcrm.project.system.customer.service.ICustomerClueService;
import com.azxcrm.project.system.order.domain.Order;
import com.azxcrm.project.system.order.service.IOrderService;
import com.azxcrm.project.system.user.domain.User;
import com.azxcrm.project.system.user.service.IUserService;

/**
 * Wap 首页模块切换
 * 
 * @author Dustyone
 * @date 2018-09-04
 */
@Controller
@RequestMapping("/wap")
public class IndexWapController {
	
	 private String prefix = "wap";

	@Autowired
	private ICustomerClueService customerClueService;
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private IOrderService orderService;

	// 系统首页客户模块
	@GetMapping("/wapCustomer")
	public String wapCustomer(Model model, CustomerClue customerClue) {
		customerClue.setClueSource(4);
		customerClue.setCluePrincipal(ShiroUtils.getUser().getUserId().intValue());
		List<CustomerClue> clue = customerClueService.selectCustomerClueList(customerClue);
		model.addAttribute("clue", clue);
		return prefix + "/customer/customer";
	}
	
	//AJAX条件查询客户线索
	@GetMapping("/getSearchValue")
	@ResponseBody
	public List<CustomerClue> getSearchValue(@RequestParam("searchValue") String searchValue) {
		CustomerClue customerClue = new CustomerClue();
		customerClue.setSearchValue(searchValue);
		List<CustomerClue> clue = customerClueService.selectCustomerClueList(customerClue);
		return clue;
	}
	
	// 系统首页我的模块
	@GetMapping("/wapMy")
	public String wapMy(Order order, Model model) {
		User user=userService.selectUserByUserId(ShiroUtils.getUserId().intValue());
		model.addAttribute("user", user);
		order.setSalesUserId(ShiroUtils.getUser().getUserId().intValue());
		order.setOrderStatus(5);
		Order countOrderId = orderService.countOrderById(order);
		model.addAttribute("countOrderId", countOrderId);
		Order countOrder = orderService.countOrder(order);
		model.addAttribute("countOrder", countOrder);
		return prefix + "/relatedme/relatedme";
	}

}
